package cn.wen.yinxiu.member.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import cn.wen.yinxiu.common.convention.result.Results;
import cn.wen.yinxiu.common.to.user.FareTO;
import cn.wen.yinxiu.common.to.user.UserAddressTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.wen.yinxiu.member.entity.AddressEntity;
import cn.wen.yinxiu.member.service.AddressService;
import cn.wen.yinxiu.common.toolkit.PageUtils;
import cn.wen.yinxiu.common.convention.result.ResultEntity;



/**
 * 用户地址
 *
 * @ClassName: AddressController
 * @Author 小飞
 * @Email coderwen22@163.com
 * @Date 2023-05-21 22:19:26
 * @Description:
 */
@RestController
@RequestMapping("member/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    /**
     * 通过用户ID获取用户的地址列表
     * @return
     */
    @GetMapping("/web/api/user/address/list")
    ResultEntity<List<UserAddressTO>> getAddress(@RequestParam("userId") Long userId) {
        List<UserAddressTO> resList = addressService.getAddressByUserId(userId);
        return Results.success(resList);
    }

    /**
     * 获取地址和运费
     * @param addrId
     * @return
     */
    @GetMapping("/web/api/user/address/fare")
    ResultEntity<FareTO> getFare(@RequestParam("addrId") Long addrId) {
        FareTO res = addressService.getAddressFare(addrId);
        return Results.success(res);
    }
}
